from langchain_community.vectorstores import FAISS

from .base import VectorBase

#
class FaissDatabase(VectorBase):


    def save_chunks_into_vectorstore(self, content_chunks, embedding_model):
        # 参考官网链接：https://python.langchain.com/docs/modules/data_connection/vectorstores/
        # ① FAISS
        # pip install faiss-gpu (如果没有GPU，那么 pip install faiss-cpu)
        vectorstore = FAISS.from_texts(texts=content_chunks,
                                       embedding=embedding_model)
        FAISS.save_local(vectorstore,"./", "faiss_index")
        return vectorstore

    def get_vectorstore(self, embedding_model):
        vectorstore = FAISS.load_local("./", embedding_model, "faiss_index", allow_dangerous_deserialization=True)
        return vectorstore

    def t(self):
        print("t")
        # ② Pinecone
        # 官网链接：https://python.langchain.com/docs/integrations/vectorstores/pinecone
        # Pinecone官网链接：https://docs.pinecone.io/docs/quickstart
        # pip install pinecone-client==2.2.2
        # 初始化
        # pinecone.init(api_key=, environment="us-east-1")
        # pc = pinecone(api_key=Keys.PINECONE_KEY)
        # 创建索引
        # index_name = "listmonktest"
        # 检查索引是否存在，如果不存在，则创建
        # if index_name not in pinecone.list_indexes():
        #     pinecone.create_index(name=index_name,
        #                           metric="cosine",
        #                           dimension=1536)
        # vectorstore = Pinecone.from_texts(texts=content_chunks,
        #                                       embedding=embedding_model,
        #                                       index_name=index_name)

        # ③ Milvus, pip install pymilvus
        # 官网链接：https://python.langchain.com/docs/integrations/vectorstores/milvus
        # vectorstore = Milvus.from_texts(texts=content_chunks,
        #                                     embedding=embedding_model,
        #                                     connection_args={"host": "localhost", "port": "19530"},
        # )
